<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $_current_user;

    protected function getCurrentUser(){
        return $this->_current_user;
    }

    protected function handleAuth($request){
        $result_arr = null;
        $sid = $request->header('sid');
        if(empty($sid)){
            $result_arr = array(
                'code'=>1,
                'message'=>'请登录'
            );
            return $result_arr;
        }else{
            $this->_current_user = DB::table('users')->where("sid", "=", $sid)->first();
            if(!$this->_current_user){
                $result_arr = array(
                    'code'=>2,
                    'message'=>'无效token，请重新登录'
                );
                return $result_arr;
            }
        }
        return $result_arr;
    }
}
